package com.smarthome.web.property.controller.deviceManager;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarthome.core.deviceManager.EquipmentDevIpcService;
import com.smarthome.domain.bean.ShEquipmentDevIpc;
import com.smarthome.domain.common.Result;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * 工控机基础管理
 * 
 * @author hgj
 *
 */
@Controller
@RequestMapping("/equipmentDevIpcController")
public class EquipmentDevIpcController {

	@Resource
	private EquipmentDevIpcService ipcService;

	/**
	 * 列表
	 * 
	 * @param devIpc
	 * @param page
	 * @return
	 */
	@RequestMapping("/dataGrid")
	@ResponseBody
	public DataGrid dataGrid(ShEquipmentDevIpc devIpc, PageHelper page) {
		return ipcService.dataGrid(devIpc, page);
	}

	/**
	 * 跳转到添加页面
	 * 
	 * @return
	 */
	@RequestMapping("/addPage")
	public String addPage(HttpServletRequest request) {
		return "/deviceManager/deviceIpcAdd";
	}

	/**
	 * 新增
	 * 
	 * @return
	 */
	@RequestMapping("/add")
	@ResponseBody
	public Result add(ShEquipmentDevIpc ipc) {
		ipcService.saveOrUpdate(ipc);
		return Result.success("操作成功！");
	}

	/**
	 * 跳转到编辑页面
	 * 
	 * @return
	 */
	@RequestMapping("/editPage")
	public String editPage(HttpServletRequest request, Long id) {
		request.setAttribute("ipc", ipcService.queryIpcById(id));
		return "/deviceManager/deviceIpcEdit";
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Result delete(Long id) {
		int num = ipcService.delete(id);
		if (num > 0) {
			return Result.success("删除成功！");
		} else {
			return Result.failure("删除失败！");
		}
	}
}
